<?php
declare(strict_types=1);


namespace App\Hoenix\Mapper;

use App\Hoenix\Model\HoenixConcubineOrder;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

/**
 * 订单Mapper类
 */
class HoenixConcubineOrderMapper extends AbstractMapper
{
    /**
     * @var HoenixConcubineOrder
     */
    public $model;

    public function assignModel()
    {
        $this->model = HoenixConcubineOrder::class;
    }

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        // 
        if (isset($params['user_id']) && filled($params['user_id'])) {
            $query->where('user_id', '=', $params['user_id']);
        }

        // 
        if (isset($params['concubine_user_id']) && filled($params['concubine_user_id'])) {
            $query->where('concubine_user_id', '=', $params['concubine_user_id']);
        }

        // 1是2否
        if (isset($params['accept']) && filled($params['accept'])) {
            $query->where('accept', '=', $params['accept']);
        }

        // 完成0否1是2毁单
        if (isset($params['complete']) && filled($params['complete'])) {
            $query->where('complete', '=', $params['complete']);
        }

        return $query->with(['concubine'])->orderByDesc('id');
    }
}